<?php

namespace app\api\controller;

use app\api\server\Order as ServerOrder;
use app\common\controller\Api;
use app\common\library\Pay;
use app\common\model\Area;
use app\common\model\Article;
use app\common\model\Banner;
use app\common\model\Circulation;
use app\common\model\Coupon;
use app\common\model\CouponLog;
use app\common\model\MoneyLog;
use app\common\model\order\Order;
use app\common\model\Problem;
use app\common\model\Province;
use app\common\model\User;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        Db::startTrans();
        try {
            $order= Order::get(100);
            // MoneyLog::frozenlog_commission($order);
            ServerOrder::add_fund_account_details($order);

        } catch (\Throwable $th) {
            Db::rollback();
        }


        $this->success('请求成功');
    }
    /**
     * @Author LK
     * @date: 2024-01-25 
     * @ApiTitle (轮播图)
     * @ApiMethod (GET)
     * @ApiParams (name="type", type="string", required=true, sample="", description="1=首页轮播,2=专区轮播")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function prefecture()
    {
        $params = request()->param();
        extract($params);
        $lunbo = Banner::all(['type' => $type]);
        $this->success('请求成功', $lunbo);
    }
    /**
     * 公告
     *
     */
    public function ad()
    {
        $ad = Article::all();
        $this->success('请求成功', $ad);
    }
    /**
     * @Author LK
     * @date: 2024-01-16 
     * @ApiTitle (公告详情)
     * @ApiMethod (GET)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="ID")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function ad_info()
    {
        $id = request()->param('id', 0);
        $ad = Article::get($id);
        $this->success('请求成功', $ad);
    }
    /**
     * @Author LK
     * @date: 2024-01-05 
     * @ApiTitle (共享金配置)
     * @ApiMethod (GET)
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function gold_config()
    {
        $circulation = Circulation::whereTime('date', 'today')->value('circulation');
        $this->success('', ['price' => $circulation ?? 0, 'rate' => config('site.conversion_ratio') ?? 0]);
    }
    /**
     * @Author LK
     * @date: 2024-01-05 
     * @ApiTitle (共享金价格趋势)
     * @ApiMethod (GET)
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function price_trend()
    {
        $circulation = Circulation::whereTime('date', '-7 days')->field('id,circulation,date')->select();
        $this->success('', $circulation);
    }
    /**
     * @Author LK
     * @date: 2024-01-23 
     * @ApiTitle (常见问题)
     * @ApiMethod (GET)
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function problem()
    {
        $list = Problem::all();
        $this->success('', $list);
    }
}
